package com.example.demo.dao.impl;
import javax.sql.DataSource;

import com.example.demo.Product;
import com.example.demo.dao.ProductDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.example.demo.Product;
import com.example.demo.dao.ProductDao;

@Repository
public class JdbcProductDao implements ProductDao {
    private final JdbcTemplate jdbcTemplate;

    @Autowired
    public JdbcProductDao(DataSource dataSource) {
        this.jdbcTemplate = new JdbcTemplate(dataSource);
    }

    @Override
    public void save(Product product) {
        String sql = "INSERT INTO product (name, description, price, image) VALUES (?, ?, ?, ?)";
        jdbcTemplate.update(sql, product.getName(), product.getDescription(), product.getPrice(), product.getImage());
    }
}